import { defineConfig } from "vite";
import react from "@vitejs/plugin-react";
import usePluginImport from "vite-plugin-importer";
// import { resolve } from "path";
// https://vite.dev/config/
export default defineConfig({
  plugins: [
    react(),
    usePluginImport({
      libraryName: "@arco-design/mobile-react",
      libraryDirectory: "esm",
      style: (path) => `${path}/style`,
    }),
    usePluginImport({
      libraryName: "@arco-design/mobile-react/esm/icon",
      libraryDirectory: "",
      camel2DashComponentName: false,
    }),
  ],
  server: {
    host: "localhost",
    port: 8090, //设置默认启动端口号
    open: true, //自动打开浏览器
    proxy: {
      "/api": {
        target: "http://127.0.0.1:8080", // 目标服务器的地址
        changeOrigin: true, // 是否需要改变原始主机头为目标URL
        rewrite: (path) => path.replace(/^\/api/, ""), // 重写路径：去掉路径中的'/api'
      },
      // 可以添加多个代理规则
      "/newApi": {
        target: "http://127.0.0.1:8080",
        changeOrigin: true,
        rewrite: (path) => path.replace(/^\/newApi/, ""),
      },
    },
  },
  resolve: {
    alias: [
      { find: /^~/, replacement: "" },
      // {
      //   "@": resolve(__dirname, "./src"),
      //   "@comp": resolve(__dirname, "./src", "components"),
      // },
    ],
  },
  css: {
    preprocessorOptions: {
      less: {
        javascriptEnabled: true,
        additionalData: `@import "@arco-design/mobile-react/style/public.less";`,
        modifyVars: {
          "@use-css-vars": true, // 开启css变量
          "@base-font-size": 50,
        },
      },
    },
  },
});
